package com.dys.test17;

/**
 * @className: com.dys.test15.ProducerThread
 * @description: 生产者线程
 * @author: pine cone
 * @version: v1.0.0
 * @createTime: 2024/08/20 下午8:28
 */
public class ProducerThread extends Thread {

    /**
     * 共享的商品
     */
    private final Product product;

    public ProducerThread(Product product) {
        this.product = product;
    }

    // 生产者生产10个商品
    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) { // i: 生产次数
            // 解决生产者和消费者打印错乱的问题
            if (i % 2 == 0) {
                product.setProduct("华为手机", "Mate70Pro");
            } else {
                product.setProduct("小米手机", "XiaoMi15Pro");
            }
        }
    }
}
